<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="p" uri="/pagination-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib prefix="security" uri="/security-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>创建<s:property value="titleName"/>信息</title> 
<script src="${staticURL}/scripts/artdialog/jquery.artDialog.js?skin=opera"></script>
<style type="text/css">
.aui_content {
	padding: 0px 0px;
}

.aui_content {
	padding-bottom: 0px !important;
	padding-left: 0px !important;
	padding-right: 0px !important;
	padding-top: 0px !important;
}

table.aui_border tbody td {
	border: none;
}
</style>

</head>
<div id="breadcrumbs">
	<div style="overflow: hidden; position: relative; width: 750px;">
		<div>
			<ul style="width: 5000px;">
				<li class="first"></li>
				<li><a href="#">商品管理</a></li>
				<li><a href="#">产品信息管理</a></li>
				<li class="last"><a href="#">创建<s:property value="titleName"/></a></li>
			</ul>
		</div>
	</div>
</div>
<div class="section">
	<jsp:include page="/common/messages.jsp" />
	<!-- ---------------------------入库单包含的数据------------------------------------ -->
		<div style="height: 40px"></div>
		<div style="margin: 10px">
			<div class="row">
			<s:hidden name="asnHeader.id" id="thisroleid" />
				<s:form namespace="/asn" method="get" 	id="searchForm">
					<table>
						<tr>
							<th>Sku 名：</th>
							<th><s:textfield name="goodsSku.name" /></th>
							<th>Sku 编码：</th>
							<th><s:textfield name="goodsSku.code" />								
							</th> 
							<th><button type="button" class="orange" onclick="searchRoleBtnClicked()"><span>查询</span></button>&nbsp;&nbsp;
							<button type="button" class="blue" onclick="backToAsnHeader(<s:property value="asnHeader.id"/>)"><span>返回</span></button>&nbsp;&nbsp;</th>
						</tr>
					</table>
				</s:form>
			</div>
			
			
			<div  id="roleInRoleListDiv" style="margin-top: 5px">
				<table id="roleInRoleList"></table> 
			    <div id="roleInRolePager"></div>   
			</div> 
		</div>
</div>


<script type="text/javascript">

function searchRoleBtnClicked(){
	var query = $('#searchForm').serialize(); // 序列化参数
	$("#roleInRoleList").jqGrid('setGridParam',{url: 'searchSkuJson.action?'+query}).trigger("reloadGrid");
}

function backToAsnHeader(id ){
	document.getElementById('searchForm').onsubmit=function(){ return false; };
	window.location.href = "${dynamicURL}/asn/updateAsnHeader.action?asnHeader.id="+id;
}

function addToAsnDetail(skuId){
	var roleid = document.getElementById('thisroleid').value; 
	var url = "${dynamicURL}/asn/addAsnDetail.action?asnHeader.id="+roleid+"&goodsSku.id="+skuId; 
	$.ajax({
		url: url,
		type: 'GET',
		success: function(data){			
			if (data.actionMessages != null && data.actionMessages != "") {
				art.dialog({
					title : '成功提示',
					time: 0.8,
					content : '' + data.actionMessages,
					esc : true,
					icon : 'succeed'
				});
				
				//$("#roleInRoleList").jqGrid().trigger('reloadGrid');
				
			} else {
				art.dialog({
					title : '失败提示',
					content : '' + data.actionErrors,
					esc : true,
					icon : 'error'
				});
			}	
			
		},
		error: function(){
			alert('ajax包含子角色过程出错！');
			return;
		}
	});
} 
	

	
$(document).ready(function (){  
 		//--------------------------------------角色包含角色-------------------------------------------------
 		var roleInRoleGridList;
 		var roleId = document.getElementById('thisroleid').value;
 		
 		roleInRoleGridList = {   
 				url: 'searchSkuJson.action',
 				colNames: ['id','名称', '编码', '属性','商品编码','单位','采购价','操作'],
				colModel: [
					        {name:'id',index:'id', frozen:true, align:"left", hidden:true},
							{name:'name',index:'name', frozen:true, align:"left"},
					   		{name:'code',index:'code', align:"left"},
					   		{name:'attributeString',index:'attributeString', align:"left", width: '200'}, 						   		
					   		{name:'itemCode',index:'itemCode', align:"center"},
					   		{name:'salesUnit',index:'salesUnit', align:"center",width: '60'},
					   		{name:'purchasePrice',index:'purchasePrice', align:"center", width: '50'},
					   		{name:'btn',index:'btn',align:"center"}
					   	], 
			   	shrinkToFit: false,
 				height: 260,
 				width: 700,
 				rowNum: 10,
 				rownumbers: true,
 				caption: '产品列表',
 				pager: '#roleInRolePager',
 				jsonReader:{
 					root:"pager.records",
 					total: "total",
 					page: "page",
 					records: "records",
 					repeatitems: false,
 					id:"0" },
 					gridComplete: function() {
 				        var grid = jQuery("#roleInRoleList");
 				        var ids = grid.jqGrid('getDataIDs');	// 获取表格所有 行id
 				        for (var i = 0; i < ids.length; i++) {
 				            var rowId = ids[i];
 				            var rowdata = grid.jqGrid('getRowData', rowId);
 				            var tempBtn = "<img title='添加到库存' style='cursor:pointer' border='0'  src='${staticURL}/default/images/add.png' onclick='addToAsnDetail("+rowdata.id+")'>";  
 				            grid.jqGrid('setRowData', rowId, { btn: tempBtn}); 
 				        } 
 				    }
 		};
  		$("#roleInRoleList").jqGrid(roleInRoleGridList);
 		$("#roleInRoleList").setGridWidth(jQuery("#roleInRoleListDiv").width() * 0.98);
});
	
</script>


</html>
